import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;

public class IstisnaMetodlari4 {

	public void cokOku() throws Exception {
		System.out.println("cokOku() metodu cagrildi");
		throw new Exception("istisna olustu"); // dikkat
	}

	public void oku() throws Exception {
		System.out.println("oku() metodu cagrildi");
		cokOku();
	}

	public static void main(String args[]) throws FileNotFoundException {
		try {
			IstisnaMetodlari4 im4 = new IstisnaMetodlari4();
			im4.oku();
		} catch (Exception ex) {
			StringWriter sw = new StringWriter();
			PrintWriter pw = new PrintWriter(sw);
			ex.printStackTrace(pw);
			System.out.println("sw.toString() : " + sw.toString());

			OutputStream os = new FileOutputStream("C:\\asd\\log.txt");
			PrintStream ps = new PrintStream(os);
			ex.printStackTrace(ps);

			ByteArrayOutputStream ba = new ByteArrayOutputStream();
			PrintStream ps2 = new PrintStream(ba);
			ex.printStackTrace(ps2);
			System.out.println("ba.toString() : " + ba);

			// trace as
			// a string

			// OutputStream yourOutputStream = null;
			// ex.printStackTrace(new PrintStream(yourOutputStream));
			// System.out.println("yourOutputStream : " + yourOutputStream);
		}
	}
}
